package com.zliblike_platform.controller;

import com.zliblike_platform.service.BookService;
import com.zliblike_platform.service.CategoryService;
import com.zliblike_platform.vo.BookVO;
import com.zliblike_platform.vo.CategoryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 搜索与分类控制器
 */
@Controller
public class SearchController {

    @Autowired
    private BookService bookService;
    
    @Autowired
    private CategoryService categoryService;
    
    /**
     * 搜索页面
     */
    @GetMapping("/search")
    public String searchPage() {
        return "search";
    }
    
    /**
     * 搜索书籍
     */
    /*@GetMapping("/api/search")
    @ResponseBody
    public List<BookVO> searchBooks(@RequestParam String keyword, 
                                    @RequestParam(required = false) Long categoryId,
                                    @RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "10") Integer size) {
        return bookService.searchBooks(keyword, categoryId, page, size);
    }*/
    
    /**
     * 分类页面
     */
    @GetMapping("/categories")
    public String categoriesPage(Model model) {
        List<CategoryVO> categories = categoryService.getAllCategories();
        model.addAttribute("categories", categories);
        return "categories";
    }
    
    /**
     * 分类详情页面
     */
    @GetMapping("/category/{categoryId}")
    public String categoryDetailPage(@PathVariable Long categoryId, Model model) {
        CategoryVO category = categoryService.getCategoryById(categoryId);
        model.addAttribute("category", category);
        return "category-detail";
    }
    
    /**
     * 获取分类下的书籍
     */
    /*@GetMapping("/api/category/{categoryId}/books")
    @ResponseBody
    public List<BookVO> getCategoryBooks(@PathVariable Long categoryId,
                                        @RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer size) {
        return bookService.getBooksByCategory(categoryId, page, size);
    }*/
} 